from PyQt5.QtWidgets import (QMessageBox, QGraphicsDropShadowEffect, 
                            QApplication, QPushButton, QWidget, QVBoxLayout)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor

class CustomMessageBox(QMessageBox):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)
        self.setStyleSheet("""
            QMessageBox {
                background-color: white;
                border: none;
                padding: 20px;
                min-width: 300px;
            }
            QMessageBox QLabel {
                color: #333333;
                font-size: 16px;
                font-weight: bold;
                margin: 15px;
            }
            QMessageBox QPushButton {
                background-color: #00A3FF;
                color: white;
                font-size: 14px;
                font-weight: bold;
                border-radius: 5px;
                padding: 8px 25px;
                min-width: 80px;
            }
            QMessageBox QPushButton:hover {
                background-color: #0090E0;
            }
        """)
        
        # 阴影效果
        shadow = QGraphicsDropShadowEffect(self)
        shadow.setBlurRadius(15)
        shadow.setColor(QColor(0, 0, 0, 150))
        shadow.setOffset(3, 3)
        self.setGraphicsEffect(shadow)

        # 初始化时创建基础按钮
        self.ok_button = self.addButton("确定", QMessageBox.AcceptRole)
        self.ok_button.clicked.connect(self.hide)

    def show_success(self, message):
        """显示成功提示"""
        self._prepare_message(message, QMessageBox.Information)

    def show_error(self, message):
        """显示失败提示"""
        self._prepare_message(message, QMessageBox.Critical)

    def _prepare_message(self, message, icon):
        """准备消息内容"""
        # 清除旧按钮（保留基础按钮）
        for btn in self.buttons():
            if btn != self.ok_button:
                self.removeButton(btn)
        
        self.setIcon(icon)
        self.setText(message)
        self.exec_()